import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postForm, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();
const path = "/ghOrder";
const ACTION_PREFIX = "GH_ORDER.";
export const query = createThunkAction(ACTION_PREFIX + "QUERY", params =>
    postJson(path + "/query", params)
);
export const showCreate = createAction(ACTION_PREFIX + "SHOW_CREATE");
export const hideCreate = createAction(ACTION_PREFIX + "HIDE_CREATE");
export const showEdit = createAction(ACTION_PREFIX + "SHOW_EDIT");
export const hideEdit = createAction(ACTION_PREFIX + "HIDE_EDIT");
export const showCreateOrderFee = createAction(ACTION_PREFIX + "SHOW_CREATE_ORDER_FEE");
export const hideCreateOrderFee = createAction(ACTION_PREFIX + "HIDE_CREATE_ORDER_FEE");
export const showUpdateOrderFee = createAction(ACTION_PREFIX + "SHOW_UPDATE_ORDER_FEE");
export const hideUpdateOrderFee = createAction(ACTION_PREFIX + "HIDE_UPDATE_ORDER_FEE");
export const showUpdateOrderOutFee = createAction(ACTION_PREFIX + "SHOW_UPDATE_ORDER_OUT_FEE");
export const hideUpdateOrderOutFee = createAction(ACTION_PREFIX + "HIDE_UPDATE_ORDER_OUT_FEE");
export const updateOrderModel = createAction(ACTION_PREFIX + "UPDATE_MODEL");
export const updateFeeList = createAction(ACTION_PREFIX + "UPDATE_FEE_LIST");
export const updateOutFeeList = createAction(ACTION_PREFIX + "UPDATE_OUT_FEE_LIST");
export const updateOrderFee = createAction(ACTION_PREFIX + "UPDATE_ORDER_FEE");
export const updateOrderOutFee = createAction(ACTION_PREFIX + "UPDATE_ORDER_OUT_FEE");
export const updateBaoGuanFeeCount = createAction(ACTION_PREFIX + "UPDATE_COUNT");
export const updateVehicleFee = createAction(ACTION_PREFIX + "GET_VEHICLE_FEE");
export const select = createAction(ACTION_PREFIX + "SELECT");
export const updateDataSource = createAction(ACTION_PREFIX + "UPDATE_DATA_SOURCE");
export const showColumns = createAction(ACTION_PREFIX + "SHOW_COLUMNS");
export const hideColumns = createAction(ACTION_PREFIX + "HIDE_COLUMNS");
export const clearFee = createAction(ACTION_PREFIX + "CLEAR_FEE");
export const updateVehicleFees = createAction(ACTION_PREFIX + "UPDATE_VEHICLE_FEES");
export const emptyCarrier = createAction(ACTION_PREFIX + "EMPTY_CARRIER");
export const clearVehicleFee = createAction(ACTION_PREFIX + "CLEAR_VEHICLE_FEE");

export const create = createThunkAction(ACTION_PREFIX + "CREATE", params =>
    postJson(path + "/create", params)
);
export const modify = createThunkAction(ACTION_PREFIX + "MODIFY", params =>
    postJson(path + "/modify", params)
);
export const modifyPart = createThunkAction(ACTION_PREFIX + "", params =>
    postJson(path + "/modifyPart", params)
);
export const calculateFee = createThunkAction(ACTION_PREFIX + "CALCULATE_FEE", params =>
    postJson(path + "/calculateFee", params)
);
export const calculateOutFee = createThunkAction(ACTION_PREFIX + "CALCULATE_OUT_FEE", params =>
    postJson(path + "/calculateOutFee", params)
);
export const getCurrencyList = createThunkAction(ACTION_PREFIX + "GET_CURRENCY", () =>
    get("/rate/currency")
);
export const getFeeList = createThunkAction(ACTION_PREFIX + "GET_FEE_LIST", () =>
    get("/feeItem/all")
);
export const getMyColumns = createThunkAction(ACTION_PREFIX + "GET_COLUMNS", params =>
    get("/customColumns/" + principal.id + "/" + params)
);
export const saveColumns = createThunkAction(ACTION_PREFIX + "SAVE_COLUMNS", params =>
    postJson("/customColumns/modify", params)
);
export const getClientList2 = createThunkAction(ACTION_PREFIX + "GET_CLIENT", params =>
    get("/client/queryByOrgId/" + params)
);
export const selectColumns = createAction(ACTION_PREFIX + "GET_COLUMNS");
export const getBusinessCodeList = createThunkAction(ACTION_PREFIX + "GET_BUSINESS_CODE_LIST", () =>
    get("/bsCode/all")
);
export const getCoach = createThunkAction(ACTION_PREFIX + "GET_COACH_LIST", () =>
    get("/coach/all")
);
export const lock = createThunkAction(ACTION_PREFIX + "LOCK", params =>
    postJson(path + "/lock/" + principal.id, params)
);
export const unlock = createThunkAction(ACTION_PREFIX + "UN_LOCK", params =>
    postJson(path + "/unlock/" + principal.id, params)
);
export const del = createThunkAction("", params =>
    get(path + "/del/" + params + "/" + principal.id)
);
export const getTransportType = createThunkAction(ACTION_PREFIX + "GET_TRANSPORT_TYPE", () =>
    get("/transportType/all")
);
export const getLines = createThunkAction(ACTION_PREFIX + "GET_LINES", params =>
    postJson("/client/getLines", params)
);
export const findFeesByClientId = createThunkAction(ACTION_PREFIX + "GET_CLIENT_FEES", params =>
    get("/client/findFeesByClientId/" + params)
);
export const getBaoGuanFeeByClientId = createThunkAction(ACTION_PREFIX + "GET_BAOGUAN_FEE", params =>
    get("/client/baoGuanFee/" + params)
);
export const getVehicleFee = createThunkAction(ACTION_PREFIX + "GET_VEHICLE_FEE", params =>
    postJson("/client/vehicleFees", params)
);
export const calculateVehicleFee = createThunkAction(ACTION_PREFIX + "CALCULATE_VEHICLE_FEE", params =>
    postJson("/ghOrder/calculateVehicleFee", params)
);
export const importGhOrder = createThunkAction(ACTION_PREFIX + "IMPORT", params =>
    postForm(path + "/import/" + params.opId, params)
);
export const importGhOrderFee = createThunkAction(ACTION_PREFIX + "IMPORT", params =>
    postForm(path + "/importFee/" + params.opId, params)
);
export const importGhOrderTransportFee = createThunkAction(ACTION_PREFIX + "IMPORT", params =>
    postForm(path + "/importTransportFee/" + params.opId, params)
);
export const reCalculateFeeById = createThunkAction(ACTION_PREFIX + "RE_CALCULATE_FEE_BY_ID", params =>
    postJson(path + "/reCalculateFeeById", params)
);
export const getById = createThunkAction(ACTION_PREFIX + "GET_BY_ID", params =>
    get(path + "/getById/" + params)
);
